package com.qdlc.p2p.dal.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dao.AdditionalUserCardDao;
import com.qdlc.p2p.dal.dto.AdditionalUserCard;
import com.qdlc.p2p.dal.model.AdditionalUserCardModel;
import com.qdlc.p2p.dal.mybatis.model.mapper.AdditionalUserCardMapper;
import com.qdlc.p2p.dal.mybatis.pager.PageProxyBuilder;
import com.qdlc.p2p.dal.mybatis.pager.core.PageParameter;

/**
 * 功能描述: 用户卡片
 * @author linya
 * @date 2016-5-6
 */
@Component
public class AdditionalUserCardDaoImpl implements AdditionalUserCardDao {

	@Resource
	AdditionalUserCardMapper additionalUserCardMapper;
	
	/**
	 * 插入记录
	 * @param record
	 * @return
	 */
	@Override
	public int save(AdditionalUserCard record){
		int count = additionalUserCardMapper.save(record);
		return count;
	}
	
    /**
     * 修改记录
     * @param record
     * @return
     */
	@Override
    public int update(AdditionalUserCard record){
    	int count = additionalUserCardMapper.update(record);
    	return count;
    }

	@Override
	public int update(int status, int preStatus, long id) {
		return additionalUserCardMapper.updateStatus(status, preStatus, id);
	}
	
	@Override
	public int useUserCard(long userId, long[] cardIds) {
		int count = additionalUserCardMapper.useUserCard(userId, cardIds);
		return count;
	}

	@Override
	public List<AdditionalUserCard> findUserCards(long userId, long[] cardIds) {
		List<AdditionalUserCard> list = additionalUserCardMapper.findUserCards(userId, cardIds);
		return list;
	}

	@Override
	public List<AdditionalUserCardModel> findUsableUserCardList() {
		return additionalUserCardMapper.findUsableUserCardList();
	}

	@Override
	public PageDataList<AdditionalUserCardModel> list(AdditionalUserCardModel model) {
		PageProxyBuilder<AdditionalUserCardMapper> builder = PageProxyBuilder.newBuilder(AdditionalUserCardMapper.class);
		builder.setPageParameter(model.getPage(), model.getRows());
		List<AdditionalUserCardModel> list = builder.createProxy().list(model);
		PageParameter page = builder.getPageParameter();
		return new PageDataList<AdditionalUserCardModel>(page.convert2Page(), list);
	}

}
